package com.xbao.controller;

import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.EmpOrgRel;
import com.xbao.model.req.OrgReq;
import com.xbao.model.vo.OrgVo;
import com.xbao.service.OrgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/8/25.
 */
@Api(value = "/org相关", tags = "org相关")
@RequestMapping(value = "org")
@Controller
@EnableAutoConfiguration
public class OrgController extends BaseController {
    @Resource
    private OrgService orgService;

    @ApiOperation(value = "addorg", notes = "addorg")
    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    public CommResult addOrg(@RequestBody CommRequest<OrgReq> orgReq) {
        orgService.addOrg(orgReq.getData());
        return result();
    }

    @ApiOperation(value = "joinOrg", notes = "joinOrg")
    @RequestMapping(value = "join",method = RequestMethod.POST)
    @ResponseBody
    public CommResult joinOrg(@RequestBody CommRequest<EmpOrgRel> orgReq) {
        orgService.joinOrg(orgReq.getData());
        return result();
    }

    @ApiOperation(value = "leaveCls", notes = "leaveCls")
    @RequestMapping(value = "leave",method = RequestMethod.POST)
    @ResponseBody
    public CommResult leaveOrg(@RequestBody CommRequest<EmpOrgRel> orgReq) {
        orgService.leaveOrg(orgReq.getData());
        return result();
    }



    @ApiOperation(value = "updateOrg", notes = "updateOrg")
    @RequestMapping(value = "update",method = RequestMethod.POST)
    @ResponseBody
    public CommResult modifyOrg(@RequestBody CommRequest<OrgReq> orgReq) {
        orgService.modifyOrg(orgReq.getData());
        return result();
    }
    @ApiOperation(value = "deleteOrg", notes = "deleteOrg")
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
    public CommResult deleteOrg(@RequestBody CommRequest<OrgReq> orgReq) {
        orgService.deleteOrg(orgReq.getData().getId());
        return result();

    }
    @ApiOperation(value = "orgDetail", notes = "orgDetail")
    @RequestMapping(value = "detail",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<OrgVo> orgDetail(@RequestBody CommRequest<OrgReq> orgReq) {
        OrgVo o = orgService.detailOrg(orgReq.getData().getId());
        return new CommResult<OrgVo>(o);

    }
    @ApiOperation(value = "orgList", notes = "orgList")
    @RequestMapping(value = "list",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<List<OrgVo>> orgList( @RequestBody CommRequest<OrgReq> orgReq) {
        List<OrgVo> vos = orgService.queryOrgs(orgReq.getData());
        return new CommResult<List<OrgVo>>(vos);

    }

    @ApiOperation(value = "mainOrg", notes = "mainOrg")
    @RequestMapping(value = "mainOrg",method = RequestMethod.POST)
    @ResponseBody
    public CommResult setMainOrg( @RequestBody CommRequest<EmpOrgRel> orgReq) {
       orgService.setMainOrg(orgReq.getData());
        return new CommResult();

    }


}
